package com.koumi.web;

import java.util.HashMap;
import java.util.Map;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.koumi.entity.Teacher;
import com.koumi.service.TeacherService;
import com.koumi.util.Constants;
import com.koumi.util.DataGrid;

@Controller
@SessionAttributes(Constants.USER_INFO_SESSION)
@RequestMapping("/manager")
public class TeacherController {
	private TeacherService teacherService;
	
	@RequestMapping("/teacherList")
	@ResponseBody
	public DataGrid getTeacherList(int page, int rows,String teacherType,String teacherName,String beginTime,String endTime){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("begin", ((page-1)*rows)+1);
		map.put("end", page*rows);
		map.put("teacherType", teacherType);
		map.put("teacherName", teacherName);
		map.put("beginTime", beginTime);
		map.put("endTime", endTime);
		return teacherService.getTeachersByPage(map);
	}
	
	@RequestMapping("/saveTeacher")
	public ModelAndView saveTeacher(Teacher teacher){
		ModelAndView mav = new ModelAndView("manager/addAudioVideo");
		boolean result = false;
		if(teacher.gettId() >0){
			result = teacherService.updateTeacher(teacher);
		} else {
			result = teacherService.addTeacher(teacher);
		}
		mav.addObject("result", result);
		return mav;
	}

	@RequestMapping("/getTeacher")
	@ResponseBody
	public Teacher getTeacher(int teacherId){
		return teacherService.getTeacherById(teacherId);
	}
	
	@RequestMapping("/deleteTeacher")
	@ResponseBody
	public boolean deleteTeacher(Teacher teacher){
		return teacherService.deleteTeacher(teacher);
	}
	
	@RequestMapping("/batchDeleteTeacher")
	@ResponseBody
	public boolean batchDeleteTeacher(int[] teacherArr){
		return teacherService.batchDeleteTeacher(teacherArr);
	}
	
	public TeacherService getTeacherService() {
		return teacherService;
	}

	public void setTeacherService(TeacherService teacherService) {
		this.teacherService = teacherService;
	}

	
}
